﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Global;
using System.IO;
using System.Xml;
using System.Text;


namespace FileSync
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            if (!File.Exists(Application.StartupPath + @"\config.ini"))
            {
                //Create ini file
                using (StreamWriter sw = new StreamWriter(Application.StartupPath + @"\config.ini", false, Encoding.UTF8))
                {

                    sw.Write(@"<?xml version=""1.0"" encoding=""utf-8""?><root>  <LibraryPath>C:</LibraryPath>  <ExtendName>ape</ExtendName>  <isSubFolders>True</isSubFolders>  <TargetPath>C:</TargetPath>  <isMove>False</isMove>  <isFolder>True</isFolder></root>");
                    sw.Close();
                }



                

            }
                loadConfig(Application.StartupPath + @"\config.ini");
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FrmMain());

            
        }
        private static void loadConfig(string ConfigFileFullName)
        {
            XmlDocument xmldoc=new XmlDocument();
            xmldoc.Load(ConfigFileFullName);
            foreach (XmlNode xn in xmldoc.ChildNodes[1].ChildNodes )
            {
                if (xn.Name == "LibraryPath")
                {
                    VariableDefine.LibraryPath = xn.InnerText;
                }
                if (xn.Name == "ExtendName")
                {
                    VariableDefine.ExtendName = xn.InnerText;
                }
                if (xn.Name == "TargetPath")
                {
                    VariableDefine.TargetPath = xn.InnerText;
                }
                if (xn.Name == "isMove")
                {
                    VariableDefine.isMove = Convert.ToBoolean(xn.InnerText);
                }
                if (xn.Name == "isFolder")
                {
                    VariableDefine.isFolder = Convert.ToBoolean(xn.InnerText);
                }
                if (xn.Name == "isSubFolders")
                {
                    VariableDefine.isSubFolders = Convert.ToBoolean(xn.InnerText);
                }
                
            }
            xmldoc = null;
        }
    }
}
